package cn.shiwei.dome.topics;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Topics {

    public static final String EXCHANGE_NAME = "exchange_name_topics";

    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建链接工厂(不设置参数, 使用默认配置)
        ConnectionFactory connectionFactory = new ConnectionFactory();

        // 获取链接
        Connection connection = connectionFactory.newConnection();

        // 获取通道
        Channel channel = connection.createChannel();

        // 获取交换机
        channel.exchangeDeclare(
                EXCHANGE_NAME, // 交换机名称
                BuiltinExchangeType.TOPIC // 交换机模式选用topic
        );

        // 通过发布信息
        channel.basicPublish(
                EXCHANGE_NAME, // 表示使用默认的交换机
                "info.#", // routingKey,
                MessageProperties.PERSISTENT_TEXT_PLAIN, // 消息持久化
                "无极".getBytes() // 发送的信息本体(需要字节数组)
        );

        System.out.println("信息发送");
    }
}
